package com.example.hp.yuejian5.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


import com.example.hp.yuejian5.R;
import com.example.hp.yuejian5.activity.Activity_DetailActivity;
import com.example.hp.yuejian5.bean.ActivityBean;
import com.example.hp.yuejian5.viewholder.ActivityViewHolder;
import com.squareup.picasso.Picasso;

import java.util.List;

import static com.example.hp.yuejian5.other.url.PICTURE;

public class ActivityAdapter extends RecyclerView.Adapter{

    private Context context;
    private LayoutInflater layoutInflater;
    private List<ActivityBean> list;

    public ActivityAdapter(Context context)
    {
        this.context=context;
        layoutInflater=LayoutInflater.from(context);
    }

    public void activityData(List<ActivityBean> list)
    {
        this.list=list;
        notifyDataSetChanged();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v=LayoutInflater.from(parent.getContext()).inflate(R.layout.acitivity_item,parent,false);
        return new ActivityViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ActivityViewHolder viewHolder=(ActivityViewHolder)holder;
        ActivityBean bean=list.get(position);
        final String id=bean.getActivity_id();

        viewHolder.activity_name.setText(bean.getActivity_title());
        viewHolder.activity_address.setText(bean.getActivity_address());
        Picasso.with(context)
                .load(PICTURE+bean.getActivity_pic())
                .into(viewHolder.activity_pic);
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context, Activity_DetailActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                Bundle bundle=new Bundle();
                intent.putExtra("a_id",id);
                context.startActivity(intent);
            }
        });
    }
    @Override
    public int getItemCount() {
        if (list==null)
        {
        return 0;
    }
     else
        {
            return list.size();
        }

    }
}
